home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / ddj1291.zip / STAT.ZIP / SOURCE.ZIP / PADISPLY.C < prev    next >
C/C++ Source or Header  |  1990-05-09  |  8KB  |  220 lines

  1. /* File:    padisply.c
  2. **
  3. **        Copyright 1990
  4. **        Fred Motteler and Applied Microsystems Corporation
  5. **        All Rights Reserved
  6. **
  7. ** Description:    Simple page oriented result display routines.
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include "padef.h"
  13.  
  14. /*
  15. ** Function:    int pa_printf(char *linebufS, FILE *outfileFP,
  16. **                  int *pagelinesNP, int line_countN)
  17. */
  18. int
  19. pa_printf(linebufS, outfileFP, pagelinesNP, line_countN)
  20. char *linebufS;            /* String to display */
  21. FILE *outfileFP;        /* Output file pointer, NULL if no file */
  22. int *pagelinesNP;        /* Pointer to the number of lines per page,
  23.                  * 0 if continuous, -1 if no display output,
  24.                  * n if n lines. */
  25. int line_countN;        /* Current page line_countN */
  26. {
  27.     int tempcharN;        /* Character returned by user */
  28.  
  29.     /* Write the string to the output file if desired */
  30.     if (outfileFP != (FILE *) NULL)
  31.     fprintf(outfileFP, linebufS);
  32.  
  33.     /* Write the string to the display if desired */
  34.     if (*pagelinesNP != (-1))
  35.     {
  36.     printf(linebufS);
  37.  
  38.     /* Check if the line contains a newline.  If so, then increment
  39.      * the value of line_countN. */
  40.     if (strchr(linebufS, '\n') != (char *) NULL)
  41.         line_countN++;
  42.  
  43.     /* Check if at the end of the page. */
  44.     if (line_countN >= *pagelinesNP)
  45.     {
  46.         printf("Press <Enter> for more, Q or q to quit");
  47.         tempcharN = getch();
  48.         /* Check if user is done looking at display */
  49.         if ((tempcharN == 'Q') || (tempcharN == 'q'))
  50.         *pagelinesNP = (-1);    /* If so, don't display any more */
  51.         printf("\n");
  52.         line_countN = 0;
  53.     }
  54.     }
  55.     return(line_countN);
  56. }
  57.  
  58. /*
  59. ** Function:    void padisplay( struct padata **bintabP, int processedN,
  60. **                int pagelinesN, FILE *outfileFP)
  61. **
  62. ** Description:    This function displays the results of the statistical
  63. **        performance analysis.  The results are contained in the padata
  64. **        structures pointed to in the table pointed to by bintabP.
  65. **        Up to the first processedN structures are displayed, unless
  66. **        a structure with a zero "hit" count is found.  The display
  67. **        stops at the first zero hit count.
  68. **
  69. **        pagelinesN gives the number of lines to display before waiting
  70. **        for a <CR> to continue.
  71. **
  72. **        pagelinesN    0    continuous output (no page breaks)
  73. **                -1    no output
  74. **                n    number of lines to display
  75. **
  76. **        outfileFP points to an optional output file for the results.
  77. **        Note that if pagelinesN = -1 and outfileFP is a valid output
  78. **        file pointer, that all output will go to the file.
  79. **
  80. **        The results are printed in the following form:
  81. **
  82. ** Module table sorted by sample counts:
  83. ** ssss samples collected
  84. **      module    samples % 0    1    2    3    4    5    6    7    8    9   10
  85. **  module_1_name   ll   xx ********************************
  86. **  module_2_name   mm   yy ****************************
  87. **  module_3_name   nn   zz ***************
  88. **    etc...        ..   .. ...
  89. **
  90. **    where:
  91. **        ssss    total number of samples in all modules
  92. **          ll    number of samples in "module_1_name"
  93. **          xx    percent of total samples in "module_1_name"
  94. **
  95. **    The row of astricks gives a rough visual display of the percentage of
  96. **    the total samples in the corresponding module.
  97. */
  98. void
  99. padisply(bintabP, processedN, pagelinesN, outfileFP)
  100. struct padata **bintabP;    /* Pointer to a table of pointers to padata
  101.                  * data structures, these structures actually
  102.                  * contain the function name, address, and
  103.                  * number of program counter hits. */
  104. int processedN;            /* Number of entries in the pointer table. */
  105. int pagelinesN;            /* Select no. of lines/page, 0 = continuous,
  106.                  * -1 = quit display */
  107. FILE *outfileFP;        /* Output file if not NULL */
  108.  
  109. {
  110.     int i,j;            /* general indices */
  111.     long max_hitsL;        /* Maximum number of hits in any single bin */
  112.     long total_hitsL;        /* Total number of hits in all bins */
  113.     int percentN;        /* Percent of total hits in any single bin */
  114.     long round_factorL;        /* 0.5% of total number of hits in all bins,
  115.                  * this is used to allow rounding instead of
  116.                  * truncation. */
  117.     int max_percentN;        /* Maximum percentage in any single bin */
  118.     int max_axisN;        /* Maximum percentage displayed on axis */
  119.     int astricksN;        /* Number of astricks to print on line */
  120.     int line_countN;        /* Number of lines on current page, error code
  121.                  * if negative. */
  122.     char linebufAB[PA_LINE_LEN]; /* staging buffer for output lines */
  123.  
  124.     /* Search for maximum hit count.  Also, find the total number of hits. */
  125.     max_hitsL = 0L;
  126.     total_hitsL = 0L;
  127.     for (i = 0; i < processedN; i++)
  128.     {
  129.         if (((bintabP[i])->hitsL) == 0L)
  130.             break;
  131.     if (((bintabP[i])->hitsL) > max_hitsL)
  132.         max_hitsL = (bintabP[i])->hitsL;
  133.     total_hitsL += (bintabP[i])->hitsL;
  134.     }
  135.     round_factorL = total_hitsL / 200L; /* Get 0.5% of total number of hits. */
  136.     max_percentN = ((max_hitsL + round_factorL) * 100L) / total_hitsL;
  137.  
  138.     line_countN = 0;
  139.     sprintf(linebufAB, "Module table sorted by sample counts:\n");
  140.     line_countN = pa_printf(linebufAB, outfileFP, &pagelinesN, line_countN);
  141.     sprintf(linebufAB, "%ld samples collected\n", total_hitsL);
  142.     line_countN = pa_printf(linebufAB, outfileFP, &pagelinesN, line_countN);
  143.     /* Determine scale along axis to print out, and appropriate scaling
  144.      * factor. */
  145.     sprintf(linebufAB, "       module    samples % ");
  146.     line_countN = pa_printf(linebufAB, outfileFP, &pagelinesN, line_countN);
  147.     if (max_percentN <= 10)
  148.     {
  149.     max_axisN = 10;
  150.     sprintf(linebufAB,
  151.         "0    1    2    3    4    5    6    7    8    9   10\n");
  152.     line_countN = pa_printf(linebufAB, outfileFP, &pagelinesN,
  153.                 line_countN);
  154.     }
  155.     else if (max_percentN <= 20)
  156.     {
  157.     max_axisN = 20;
  158.     sprintf(linebufAB,
  159.         "0    2    4    6    8   10   12   14   16   18   20\n");
  160.     line_countN = pa_printf(linebufAB, outfileFP, &pagelinesN,
  161.                 line_countN);
  162.     }
  163.     else if (max_percentN <= 30)
  164.     {
  165.     max_axisN = 30;
  166.     sprintf(linebufAB,
  167.         "0       5       10      15      20       25      30\n");
  168.     line_countN = pa_printf(linebufAB, outfileFP, &pagelinesN,
  169.                 line_countN);
  170.     }
  171.     else if (max_percentN <= 50)
  172.     {
  173.     max_axisN = 50;
  174.     sprintf(linebufAB,
  175.         "0    5   10   15   20   25   30   35   40   45   50\n");
  176.     line_countN = pa_printf(linebufAB, outfileFP, &pagelinesN,
  177.                 line_countN);
  178.     }
  179.     else if (max_percentN <= 100)
  180.     {
  181.     max_axisN = 100;
  182.     sprintf(linebufAB,
  183.         "0   10   20   30   40   50   60   70   80   90  100\n");
  184.     line_countN = pa_printf(linebufAB, outfileFP, &pagelinesN,
  185.                 line_countN);
  186.     }
  187.  
  188.     /* Display the data */
  189.     for (i = 0; i < processedN; i++)
  190.     {
  191.     /* Quit at first bin with zero hits. */
  192.         if (((bintabP[i])->hitsL) == 0L)
  193.             break;
  194.         /* Calculate the percent of hits in the bin.  Include adding in a
  195.          * constant that allows rounding instead of truncation to the nearest
  196.          * percent. */
  197.         percentN =
  198.         ((((bintabP[i])->hitsL) + round_factorL) * 100L) / total_hitsL;
  199.     /* Print the module name, the actual number of hits, and the percent */
  200.     sprintf(linebufAB, "%16s %5ld %3d ",
  201.         ((bintabP[i])->symbolAB),
  202.         ((bintabP[i])->hitsL),
  203.         percentN);
  204.     line_countN = pa_printf(linebufAB, outfileFP, &pagelinesN,
  205.                 line_countN);
  206.     /* Print a row of astricks proportional to the percent */
  207.     astricksN = (percentN * 52) / max_axisN;
  208.     for (j = 0; j < astricksN; j++)
  209.     {
  210.         sprintf(linebufAB, "*");
  211.         line_countN = pa_printf(linebufAB, outfileFP, &pagelinesN,
  212.                     line_countN);
  213.     }
  214.     sprintf(linebufAB, "\n");
  215.     line_countN = pa_printf(linebufAB, outfileFP, &pagelinesN,
  216.                 line_countN);
  217.     }
  218.     return;
  219. }
  220.